﻿@using SCMS.Resource
@model SCMS.UI.Models.ViewExpsClaims
@{AjaxOptions ajaxOpts = new AjaxOptions
  {
      UpdateTargetId = "popup-page",
      LoadingElementId = "popup-loading",
      HttpMethod = "Post",
      Url = Url.Action("ApproveECF"),
      OnBegin = "return VerifyBLBalance(" + Model.ExpenseClaimItems.Count + ")",
      OnSuccess = "ReviewComplete('" + string.Format(Resources.RequestReview_String_ApprovedMsg, Model.EntityExpseRqst.RefNumber) + "', '" + Resources.RequestReview_String_ECFApprovalComplete + "')"
  };}
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

@using (Ajax.BeginForm(null, null, ajaxOpts, new { @class = "form" }))
{
    @Html.ValidationSummary(true)
    <h4 style="text-align: center;">@Resources.Global_String_ExpenseClaim.ToUpper()</h4>
    <center><b>@Model.EntityExpseRqst.RefNumber</b></center>
    <br />
    <table width="98%" align="center" cellspacing="0" cellpadding="0" border="1" class="cardTable">
        <tr class="gridheader">
            <th align="center" width="33%">
                @Resources.Global_String_Date
            </th>
            <th align="center" width="33%">
                @Resources.ExpenseClaim_LoadExpenseClaim_ExpenseCurrency
            </th>
            <th align="center" width="34%">
                @Resources.ExpenseClaim_ViewExpsClaimsDetails_ConvertedTo
            </th>
        </tr>
        <tr class="gridodd">
            <td align="center">
                @Model.EntityExpseRqst.RequestDate.ToString("dd/MM/yyyy")
                @Html.HiddenFor(e => e.EntityExpseRqst.Id)
            </td>
            <td align="center">
                @Model.ExpsCurrency.ShortName
                @Html.HiddenFor(e => e.EntityExpseRqst.ExpenseCurrencyId)
                <input type="hidden" id="expenseCurrency" value="@Model.ExpsCurrency.ShortName" />
                <input type="hidden" id="currencyId" value="@Model.ExpsCurrency.Id" />
            </td>
            <td align="center">
                @Html.DropDownListFor(e => e.ConversionCurrencyId, Model.Currencies, new { @id = "convCurrencyId", @onchange = "javascript:onChangeCurrency()" })
                @Html.ValidationMessageFor(e => e.ConversionCurrencyId)
            </td>
        </tr>
        <tr class="gridheader">
            <th align="center">
                @Resources.ExpenseClaim_LoadExpenseClaim_ClaimBy
            </th>
            <th align="center">
                @Resources.Global_String_Title
            </th>
            <th align="center">
                @Resources.ExpenseClaim_ViewExpsClaimsDetails_RateOfConversion
            </th>
        </tr>
        <tr class="gridodd">
            <td align="center">
                @Model.EntityExpseRqst.Staff1.Person.FirstName &nbsp; @Model.EntityExpseRqst.Staff1.Person.OtherNames
            </td>
            <td align="center">
                @Model.EntityExpseRqst.Staff1.Designation.Name
            </td>
            <td align="center">
                @Html.TextBoxFor(e => e.ConversionRate, new { @id = "conversionRate", @class = "numericTb", @onblur = "javascript:changeECFExRate()" })
                @Html.ValidationMessageFor(e => e.ConversionRate)
            </td>
        </tr>
    </table>
    <table width="98%" align="center" cellspacing="0" cellpadding="0">
        <tr>
            <td width="33%">&nbsp;</td>
            <td width="33%">&nbsp;</td>
            <td id="fxRateInfo" align="center" width="34%" style="font-size: smaller; font-style: italic; font-weight: bold;">
                
            </td>
        </tr>
    </table>
    <br />
    <p id="budgetCheckStatus"></p>
    <table width="98%" align="center" cellspacing="0" cellpadding="0" border="1" class="cardTable">
        <tr class="gridheader">
            <th rowspan="2">
                @Resources.Global_String_Description
            </th>
            <th colspan="3">
                @Resources.ExpenseClaim_LoadExpenseClaim_Coding
            </th>
            <th>
                @Resources.Global_String_Transaction
            </th>
            <th>
                @Resources.ExpenseClaim_ViewExpsClaimsDetails_CurrencyConversion
            </th>
        </tr>
        <tr class="gridheader">
            <th>
                @Resources.ExpenseClaim_ViewExpsClaimsDetails_AccountCode
            </th>
            <th>
                @Resources.Budget_CategoryList_ProjectNo
            </th>
            <th>
                @Resources.Budget_CreateSubLine_LineNumber
            </th>
            <th>
                @Resources.Global_String_Amount
            </th>
            <th>
                @Resources.ExpenseClaim_ViewExpsClaimsDetails_ConvertedAmount
            </th>
        </tr>
        @{
    int num = 0; string pbDiv = ""; string rowId = "";
    for (int i = 0; i < Model.ExpenseClaimItems.Count; i++)
    {
        num = i + 1;
        pbDiv = "PBlines" + num;
        rowId = "row" + i;
            <tr id="@rowId">
                <td style="text-align: left;">
                    @Model.ExpenseClaimItems[i].EntityExpseItem.ItemDescription
                    @Html.HiddenFor(e => Model.ExpenseClaimItems[i].EntityExpseItem.Id)
                </td>
                <td style="text-align: left;">
                    @Html.DropDownListFor(e => Model.ExpenseClaimItems[i].AccountCode, Model.ExpenseClaimItems[i].AccountCodes)
                </td>
                <td style="text-align: left;">
                    @Html.DropDownListFor(e => Model.ExpenseClaimItems[i].ProjectDonorId, Model.ExpenseClaimItems[i].ProjectDonors, new { @onchange = "onChangeProjectNoForECF(this," + num + ")" })
                </td>
                <td style="text-align: left;">
                    <div id="@pbDiv">
                        @Html.DropDownListFor(e => Model.ExpenseClaimItems[i].BudgetLineId, Model.ExpenseClaimItems[i].BudgetLines, new { onchange = "javascript:checkBalance4Review(this)" })
                        @Html.ValidationMessageFor(e => Model.ExpenseClaimItems[i].BudgetLineId)
                    </div>
                </td>
                <td style="text-align: right;">
                    @Html.TextBoxFor(e => Model.ExpenseClaimItems[i].Amount, new { @class = "numericTb", @id = "totalPrice" + i, @onblur = "javascript:changeECFExRate()" })
                    @Html.ValidationMessageFor(e => Model.ExpenseClaimItems[i].Amount)
                </td>
                <td style="text-align: right;">
                    @Html.TextBoxFor(e => Model.ExpenseClaimItems[i].EntityExpseItem.ConvertedAmount, new { @class = "numericTb", @id = "convPrice" + i, @readonly = "readonly" })
                </td>
            </tr>
    }
        }
        <tr>
            <td colspan="2" class="gridheader" align="right">
                @Resources.RequestReview_String_CurrencyOfECF
            </td>
            <td align="center">
                @Model.ExpsCurrency.ShortName
            </td>
            <td class="gridheader" align="right">
                @Resources.Global_String_Total    
            </td>
            <td align="right">
                @Html.TextBoxFor(e => e.EntityExpseRqst.TotalValue, new { @id = "totalVal", @class = "numericTb", @readonly = "readonly" })
            </td>
            <td align="right">
                <input type="text" class="numericTb" id="totalAmount" name="totalConvVal" readonly="readonly" />
            </td>
        </tr>
        <tr>
            <td colspan="2" class="gridheader3" align="right">
                @Resources.Global_String_MasterBudgetCurrency
            </td>
            <td align="center">
                @Html.DropDownListFor(e => e.MBCurrencyId, Model.Currencies, new { @class = "smallControl", @id = "mbCurrencyId", @onchange = "calculateMBValue()" })
            </td>
            <td class="gridheader3" align="right">
                @Resources.Global_String_MasterBudgetValue
            </td>
            <td align="right">
                @Html.TextBoxFor(e => e.MBValue, new { @id = "mbValue", @class = "numericTb" })
            </td>
            <td class="gridheader3">
                @Resources.RequestReview_String_ECFValue
                <input type="hidden" id="origLocalValue" />
                <input type="hidden" id="origFxValue" />
                <input type="hidden" id="ecfItemCount" value="@Model.ExpenseClaimItems.Count" />
            </td>
        </tr>
    </table>
    if (Model.BudgetCheckResults != null && Model.BudgetCheckResults.Count > 0)
    {
        <br />
        <input type="hidden" id="fundsInsufficientFor" value="ECF" />
        <center style="text-align: center; color: Red; font-weight: bold; font-style: italic;">@Resources_frank.ExpenseClaim_LoadECFItems_FundsUnavailableMessage</center>
        <table align="center" class="cardTable">
            <tr>
                <th>@Resources.Budget_CategoryList_ProjectNo</th>
                <th>@Resources.Budget_CreateSubLine_LineNumber</th>
                <th>@Resources.MasterBudget_MasterBudget_FundsAvailable</th>
                <th>@Resources_frank.RequestReview_ReviewRFP_RequestAmount</th>
            </tr>
            @foreach (var bcr in Model.BudgetCheckResults)
            {
                <tr>
                    <td>@bcr.ProjectBudget.BudgetCategory.ProjectDonor.ProjectNumber</td>
                    <td>@bcr.ProjectBudget.LineNumber @bcr.ProjectBudget.Description</td>
                    <td style="color: Red; font-weight: bold;" align="right">@bcr.AvailableAmount.ToString("#,##0.00")</td>
                    <td align="right">@bcr.AmountChecked.ToString("#,##0.00")</td>
                </tr>
            }
        </table>
    }
    <br />
    <table width="98%" align="center">
        <tr>
            <td width="50%" align="right">
                <input type="submit" value="@Resources.Global_String_Approve" class="btn tertiary" />
            </td>
            <td width="50%">
                <input type="button" class="btn tertiary" value=" @Resources.Global_String_Reject " onclick="sendRequest('/RequestReview/LoadRejectECF/@Model.EntityExpseRqst.Id', 'popup-page', 'popup-loading'); CenterPopup();" />
            </td>
        </tr>   
    </table>
}
